#include "channel.h"


int httpd_write_channel(int sock, http_channel_t *send_buf, int send_len)
{
    struct msghdr msg;
    struct iovec iov[1];        
    
    bzero(&msg, sizeof(msg));
    msg.msg_name = NULL;        /* attention this is a pointer to void* type */
    msg.msg_namelen = 0;         
        
    iov[0].iov_base = (char *) send_buf;
    iov[0].iov_len = send_len;
    
    msg.msg_iov = iov;
    msg.msg_iovlen = 1;        

    return sendmsg( sock, &msg, 0 );
}


int httpd_read_channel(int sock, http_channel_t *recv_buf, int recv_len)
{
    struct msghdr msgr;
    struct iovec iovr[1];      
      
    bzero(&msgr, sizeof(msgr));
    bzero(recv_buf, recv_len);
    
    msgr.msg_name = NULL;        // attention this is a pointer to void* type
    msgr.msg_namelen = 0;
        
    iovr[0].iov_base = (char*) recv_buf;
    iovr[0].iov_len = recv_len;
    
    msgr.msg_iov = iovr;    
    msgr.msg_iovlen = 1; 

    return recvmsg(  sock, &msgr, 0);               
}

